package com.gyhy.dumplings.customer.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyhy.dumplings.common.vo.SocialUser;
import com.gyhy.dumplings.customer.dao.CustomerDao;
import com.gyhy.dumplings.customer.entity.CustomerEntity;
import com.gyhy.dumplings.customer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @description:
 * @author: 光影灰翼
 * @date: 2022-09-19 8:16
 * @version: 1.0
 * @email: 978330688@qq.com
 */
@Service
public class CustomerServiceImpl  extends ServiceImpl<CustomerDao, CustomerEntity> implements CustomerService {

    @Autowired
    private CustomerDao customerDao;
    @Override
    public CustomerEntity login(SocialUser socialUser) {

        Integer giteeId = socialUser.getId();
        System.out.println("giteeId="+giteeId);
        //1、判断当前社交用户是否已经登录过系统
        CustomerEntity customerEntity = this.baseMapper.selectOne(new QueryWrapper<CustomerEntity>().eq("gitee_id", giteeId));

        if (customerEntity != null) {
            //2.1、这个用户已经注册过
            //直接返回信息
            System.out.println(customerEntity);
            return customerEntity;
        } else {
            //2.2、没有查到当前社交用户对应的记录我们就需要注册一个
            CustomerEntity register = new CustomerEntity();

            register.setGiteeId(socialUser.getId());
            register.setUsername(socialUser.getName());
            this.baseMapper.insert(register);
            return register;
            }
        }

    @Override
    public CustomerEntity test() {
        return customerDao.selectOne(new QueryWrapper<CustomerEntity>().eq("gitee_id", 8463271));
    }
}
